package com.example.springboot1.utils;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;

import java.math.BigDecimal;
import java.util.*;

/**
 * @author ckj
 * @description
 * @date 2023-09-11 14:54
 */


public class CostCalKit {

    private String rate;
    private String rate1;
    private Integer limit;
    private String yearDay;

    public static Map<String, BigDecimal> calCost(BigDecimal amount, List<String> projectIds, String projectId) {
        Map<String, BigDecimal> result = new HashMap<>();
        BigDecimal divide = amount.divide(BigDecimal.valueOf(projectIds.size()), 2, BigDecimal.ROUND_HALF_UP);
        for (String item : projectIds) {
            if (Objects.equals(projectId, item)) {
                BigDecimal subtract = amount.subtract(divide.multiply(BigDecimal.valueOf(projectIds.size() - 1)));
                result.put(item, subtract);
            } else {
                result.put(item, divide);
            }
        }
        return result;
    }

    public static BigDecimal calDayCost(BigDecimal amount, Date purchaseDate, BigDecimal checkAmount) {
        long between = DateUtil.between(purchaseDate, new Date(), DateUnit.DAY);

        BigDecimal costAmount = amount.divide(BigDecimal.valueOf(5).multiply(BigDecimal.valueOf(365)), 2, BigDecimal.ROUND_HALF_UP)
                .multiply(new BigDecimal("1.18")).setScale(2,BigDecimal.ROUND_HALF_UP);
        BigDecimal divide = checkAmount.divide(BigDecimal.valueOf(365),2, BigDecimal.ROUND_HALF_UP);

        BigDecimal add = costAmount.add(divide);
        return add;

    }

    public static void main(String[] args) {
        BigDecimal bigDecimal = BigDecimal.valueOf(100);
        calCost(bigDecimal, Arrays.asList("1", "2", "3"), "1");
        Date parse = DateUtil.parse("2023-09-11");
        calDayCost(new BigDecimal("500.25"),parse,new BigDecimal("155.25"));

    }
}
